﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace DDD4Fun.Observer
{
    //被观察者实现
    public class ObservableImpl:IObservable
    {
        protected Hashtable ObserverContainer = new Hashtable();

        #region IObservable Members

        public void Register(IObserver anObserver)
        {
            ObserverContainer.Add(anObserver, anObserver);
        }

        public void UnRegister(IObserver anObserver)
        {
            ObserverContainer.Remove(anObserver);
        }

        #endregion

        public void NotifyObservers(object anObject)
        {
            foreach (IObserver Observer in ObserverContainer.Keys)
            {
                Observer.Notify(anObject);
            }
        }
    }
}
